package com.ttt.controller;

import com.ttt.pojo.User;
import com.ttt.servicer.impl.UserServiceImpl;
import com.ttt.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("user")
@CrossOrigin  //跨域资源共享
public class UserController {

    @Autowired
    private UserServiceImpl userService;
    private Result result;

    //用户登录
    @PostMapping("/login")
    public Result login(@RequestBody User user){
        System.out.println("用户名：" + user.getUsername());
        System.out.println("密码：" + user.getPassword());
        //将请求的username、password 发送给业务层
        //调用UserServiceImpl的方法
        result = userService.findUserLogin(user);
        System.out.println("result" + result);
        return result;

    }

    //用户注册
    @PostMapping("/register")
    public Result register(@RequestBody User user){
        System.out.println("用户名：" + user.getUsername());
        System.out.println("手机号：" + user.getPhone());
        System.out.println("密码：" + user.getPassword());

        //调用service层的代码，进行注册验证
        result = userService.register(user);
        return result;
    }




}
